package stuff;

import java.util.ArrayList;
import java.util.List;

import model.Month;


/**
 * This class holds the information for a Month and all of the days and their
 * appointments. The days are held in an array list. The months are of type
 * month, and the years are type in.
 * 
 * @author Matthew Edwards
 * @version 3-5-11
 */
public class AppointmentMonth {
    
    private final List<AppointmentDay> days;

    private Month month;
    
    private int year;

	/**
	 * This constructor creates a new month and the year. It creates the
	 * arraylist called days and calls the setupDays method.
	 */
    public AppointmentMonth(Month month, int year){
    	this.month = month;
    	this.year = year;
        days = new ArrayList<AppointmentDay>();
        setupDays();
    }

	/**
	 * This method sets up the days in each month so that there are the correct
	 * number of days per given month. The method uses the toString method to
	 * extract the string of the month and uses that for the for loops. From
	 * there, the method uses for loops starting at one and ends at the correct
	 * number of days. For example, February only has 28 days and stops adding
	 * days when it hits 28. It adds a day for every loop.
	 */
    private void setupDays(){
    	final String mon = month.toString();
    	if("January".equals(mon)){
    		addDays(31);
    	}else if("February".equals(mon)){
    		final int leapYear = year % 4;
    		if(leapYear == 0){
    			addDays(29);
    		}else{
    			addDays(28);
    		}
    	}else if("March".equals(mon)){
    		addDays(31);
    	}else if("April".equals(mon)){
    		addDays(30);
    	}else if("May".equals(mon)){
    		addDays(31);
    	}else if("June".equals(mon)){
    		addDays(30);
    	}else if("July".equals(mon)){
    		addDays(31);
    	}else if("August".equals(mon)){
    		addDays(31);
    	}else if("September".equals(mon)){
    		addDays(30);
    	}else if("October".equals(mon)){
    		addDays(31);
    	}else if("November".equals(mon)){
    		addDays(30);
    	}else if("December".equals(mon)){
    		addDays(31);
    	}
    }
    
    private void addDays(int numDays){
    	for(int i = 1; i <= numDays; i++){
    		days.add(new AppointmentDay(i));
    	}
    }
    
    /**
     * This getter gets the name of the month and returns it as a string. 
     * 
     * @return The name of the month as a string. 
     */
    public String getMonth(){
    	return month.toString();
    }
    
    /**
     * This getter gets the year and returns it as an int. 
     * 
     * @return The year as an int for use for other classes. 
     */
    public int getYear(){
    	return year;
    }
    
    /**
     * Gets the days inside the array list and returns it as a list. 
     * 
     * @return Returns the days of the Appointment in the arraylist as a list.  
     */
    public List<AppointmentDay> getDays(){
        return days;
    }
    
}